<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        canvas {
            border: 1px solid red;
        }
    </style>
</head>

<body>
    <canvas width="600" height="400" id="canvas"></canvas>
</body>
<script>
    var cav = document.getElementById('canvas')
const ctx = cav.getContext('2d');

// 描边矩形

ctx.strokeStyle = "#d545ef"
ctx.strokeRect(50,50,100,80)


//填充矩形
ctx.fillStyle = '#ef356c'

ctx.fillRect(150,150,100,80)


ctx.fillStyle = '#FFE8E8'
ctx.fillRect(50,50,100,80)

// rect实现

ctx.fillStyle = '#FFE8E8'
ctx.strokeStyle = 'skyblue'
ctx.rect(200,200,80,80)
ctx.stroke()
ctx.fill()

//清楚矩形
ctx.clearRect(60,60,50,50)

//清空canvas
ctx.clearRect(0,0,cav.width,cav.height)
</script>

</html>